﻿﻿﻿﻿<template>
  <el-container class="home-container">

      <el-menu  @open="handleOpen" @close="handleClose" :collapse="isCollapse"
                :default-active="$route.path"
                class="el-menu-vertical-demo"
                router
                background-color="#333744"
                text-color="#fff"
                active-text-color="#409eff"
      >
        <el-menu-item index="/home">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="/home/AreaMonitor">
          <i class="el-icon-user-solid"></i>
          <span slot="title">校内区域监控</span>
        </el-menu-item>
          <el-menu-item index="/home/record">
            <i class="el-icon-user-solid"></i>
            <span slot="title">通行记录</span>
          </el-menu-item>
          <el-menu-item index="/home/person">
            <i class="el-icon-user-solid"></i>
            <span slot="title">人员信息</span>
          </el-menu-item>
          <el-menu-item index="/home/area">
            <i class="el-icon-user-solid"></i>
            <span slot="title">区域信息</span>
          </el-menu-item>
          <el-menu-item index="/home/user">
            <i class="el-icon-user-solid"></i>
            <span slot="title">用户信息</span>
          </el-menu-item>
      </el-menu>

    <el-container>
      <el-header>
        <div>
          <img style="width: 50px; height: 50px" src="../assets/zut.png" alt />
          <span>疫情二维码系统</span>
          <el-button class="el-icon-s-fold" @click="isC()" style="background-color: #333744;border:none;"></el-button>
        </div>
        <div style="font-family: electronicFont;color: #ffeb7b;font-size: 21px;">
          {{ nowDate }}{{ nowWeek }}{{ nowTime }}
        </div>
      </el-header>
      <el-main  style="padding:1px;" >
        <router-view> </router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      name: null,
      nowDate: "", // 当前日期
      nowTime: "", // 当前时间
      nowWeek: "", // 当前星期
    };
  },
  //onload事件
  created() {
    //回车监听事件
    var _this = this;
    document.onkeydown = function(e) {
      let key = window.event.keyCode;
      if (key == 13) {
        _this.login();
      }
    };
    //const _this = this
    _this.name = window.sessionStorage.getItem("name");
  },
  methods: {
    isC(){
      this.isCollapse = !this.isCollapse
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    dealWithTime(data) {
      // 获取当前时间
      let formatDateTime;
      let Y = data.getFullYear();
      let M = data.getMonth() + 1;
      let D = data.getDate();
      let H = data.getHours();
      let Min = data.getMinutes();
      let S = data.getSeconds();
      let W = data.getDay();
      H = H < 10 ? "0" + H : H;
      Min = Min < 10 ? "0" + Min : Min;
      S = S < 10 ? "0" + S : S;
      switch (W) {
        case 0:
          W = "日";
          break;
        case 1:
          W = "一";
          break;
        case 2:
          W = "二";
          break;
        case 3:
          W = "三";
          break;
        case 4:
          W = "四";
          break;
        case 5:
          W = "五";
          break;
        case 6:
          W = "六";
          break;
        default:
          break;
      }
      this.nowDate = Y + "年" + M + "月" + D + "日 ";
      this.nowWeek = "周" + W;
      this.nowTime = H + ":" + Min + ":" + S;
      // formatDateTime = Y + "年" + M + "月" + D + "日 " + " 周" +W + H + ":" + Min + ":" + S;
    },
  },
  mounted() {
    // 页面加载完后显示当前时间
    this.dealWithTime(new Date());
    // 定时刷新时间
    this.timer = setInterval(() => {
      this.dealWithTime(new Date()); // 修改数据date
    }, 500);
  },
  destroyed() {
    if (this.timer) {
      // 注意在vue实例销毁前，清除我们的定时器
      clearInterval(this.timer);
    }
  },
};
</script>
<style lang="less" scoped>
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
  }
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between; // 左右贴边
  padding-left: 0%; // 左边界
  align-items: center; // 水平
  color: #fff;
  font-size: 20px;

  > div {
    //左侧div加布局
    display: flex;
    align-items: center;

    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #333744;

  .el-menu {
    border-right: none; // 对其右边框
  }
}

.el-main {
  background-color: #eaedf1;
}

.home-container {
  height: 100%;
}

.logo_img {
  width: 20%;
  height: 100%;
}

.iconfont {
  margin-right: 10px;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer; // 显示鼠标指针为：小手
}
</style>
